package cn.udrm.water.base.v1.manager.repository;

import java.util.List;

import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import cn.udrm.water.base.v1.manager.entities.BaseResource;

@Repository
public interface BaseResourceRepository extends JpaRepository<BaseResource, String> {
	
	
	@EntityGraph(value="BaseResource.childrens", type=EntityGraphType.FETCH)
	public List<BaseResource> findByParentIsNull();

	@EntityGraph(value="BaseResource.roles", type=EntityGraphType.FETCH)
	@Query(value="FROM BaseResource b WHERE b.id=?1")
	public BaseResource getWithRolesById(String id);
	
	@EntityGraph(value="BaseResource.childrens", type=EntityGraphType.FETCH)
	@Query(value="FROM BaseResource b WHERE b.id=?1")
	public BaseResource getWithChildrensById(String id);
	
	@Query(value="FROM BaseResource b WHERE b.id=?1")
	public BaseResource findSelfById(String id);
}
